#include <cstdio>

int n, p[ 100 ], m[ 100 ], f[ 3333 ], sum;
bool can;

void init( )
{
    int i;
    sum = 0;
    can = false;
    for ( i = 0; i < n; i++ )
    {
        scanf("%d%d", &p[ i ], &m[ i ]);
        sum += p[ i ] * m[ i ];
    }
    for ( i = 1; i <= sum / 3; i++ )
        f[ i ] = 0;
    f[ 0 ] = 1;
}

void work( )
{
    int i, j, k;
    if ( sum % 3 != 0 )
        return ;
    sum /= 3;
    for ( i = 0; i < n; i++ )
    {
        if ( f[ sum ] != 0 )
            can = true;
        for ( j = sum; j >= p[ i ]; j-- )
            for ( k = j - p[ i ]; k >= j - p[ i ] * m[ i ] && k >= 0; k -= p[ i ])
                f[ j ] = ( f[ j ] + f[ k ] ) % 10000;
    }
}

void print( )
{
    if ( can )
        printf("%d\n", f[ sum ]);
    else
        printf("sorry\n");
}

int main( )
{
    while ( scanf("%d", &n) && n )
    {
        init( );
        work( );
        print( );
    }
    return 0;
}
